$(document).ready(function(){
 
});

function openPartner()
{
    $('#partner_popup_flash').html('');
    $('#partner_popup_type').val('');
    $("#partner_popup_family_name").val('');
    $("#partner_popup_last_name").val('');
    $("#partner_popup_first_name").val('');
    $("#partner_popup_register_number").val('');
    $("#partner_popup_address_1").val('');
    $("#partner_popup_address_2").val('');
    $("#partner_popup_address_full").val('');
    $("#partner_popup_phone").val('');
    $("#partner_popup_email").val('');
}

function addPartner()
{
    var partner_popup_type = $('#partner_popup_type').val();
    var partner_popup_family_name = $('#partner_popup_family_name').val();
    var partner_popup_last_name = $('#partner_popup_last_name').val();
    var partner_popup_first_name = $('#partner_popup_first_name').val();
    var partner_popup_register_number = $('#partner_popup_register_number').val();
    var partner_popup_address_1 = $('#partner_popup_address_1').val();
    var partner_popup_address_2 = $('#partner_popup_address_2').val();
    var partner_popup_address_full = $('#partner_popup_address_full').val();
    var partner_popup_phone = $('#partner_popup_phone').val();
    var partner_popup_email = $('#partner_popup_email').val();
    
    
    if(partner_popup_type.length > 0 && partner_popup_last_name.length > 0 && partner_popup_first_name.length > 0 && partner_popup_register_number.length > 0 && partner_popup_phone.length > 0)
    {
    
        var hiddenPartnerCount = parseInt($("#hiddenPartnerCount").val());
        hiddenPartnerCount++;
        var partnerList = '<tr class="partnerListRow"><td>'+hiddenPartnerCount+'\
    <input type="hidden" name="partner_type[]" value="'+partner_popup_type+'">\n\
    <input type="hidden" name="partner_popup_family_name[]" value="'+partner_popup_family_name+'">\n\
    <input type="hidden" name="partner_popup_last_name[]" value="'+partner_popup_last_name+'">\n\
    <input type="hidden" name="partner_popup_address_1[]" value="'+partner_popup_address_1+'">\n\
    <input type="hidden" name="partner_popup_address_2[]" value="'+partner_popup_address_2+'">\n\
    <input type="hidden" name="partner_popup_address_full[]" value="'+partner_popup_address_full+'">\n\
    <input type="hidden" name="partner_popup_email[]" value="'+partner_popup_email+'">\n\
    </td><td>'+partner_popup_first_name+'<input type="hidden" name="partner_popup_first_name[]" value="'+partner_popup_first_name+'"></td><td>'+partner_popup_register_number+'<input type="hidden" name="partner_popup_register_number[]" value="'+partner_popup_register_number+'"></td><td><input type="hidden" name="partner_popup_phone[]" value="'+partner_popup_phone+'">'+partner_popup_phone+'</td></tr>';

        if(hiddenPartnerCount === 1)
        {
            $("#partnerTableTbody").html(partnerList);
        }else{
            $(".partnerListRow:last").after(partnerList);
        }
        $("#hiddenPartnerCount").val(hiddenPartnerCount);

        $('#partnerAddPopup').modal('hide');
    }else{
        $('#partner_popup_flash').html('<label class="required">Улаанаар тэмдэглэсэн талбаруудыг заавал бөглөнө үү.</label>');
    }
    
}